﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainDriver.DomainModeling.DataProviders;
using DomainDriver.DomainModeling.DomainModels;
using DomainDriver.DomainModeling.DomainObjects;
using DomainDriver.DomainModeling.GenericUnitTesting.Repositories;
using AutomotivePricingModel.Companies;
using AutomotivePricingModel.UnitTests.Repositories;

namespace AutomotivePricingModel.UnitTests.CmdExe
{
    public delegate void TestMethod();

    class Program
    {
        static void Main(string[] args)
        {
            var persistenceTypeToUse = DataSourcePersistenceType.Database;

            var repositoryTests = new CompanyRepositoryTests(persistenceTypeToUse);
            var testMethods = GetTestMethods<AutomotivePricingDomainModel, Guid, Company>(repositoryTests);

            foreach (var testMethod in testMethods)
            {
                repositoryTests.SetUp();
                testMethod();
                repositoryTests.TearDown();
            }
        }

        public static ICollection<TestMethod> GetTestMethods<DOMAIN_MODEL, KEY, KEYED_DOMAIN_OBJECT>(RepositoryTestFixture<DOMAIN_MODEL, KEY, KEYED_DOMAIN_OBJECT> testFixture)
            where DOMAIN_MODEL : class, IDomainModel
            where KEYED_DOMAIN_OBJECT : IKeyedDomainObject<KEY, KEYED_DOMAIN_OBJECT>
        {
            var testMethods = new List<TestMethod>();

            testMethods.Add(new TestMethod(testFixture.VerifyRepositoryAfterInitialization));
            testMethods.Add(new TestMethod(testFixture.VerifyRepositoryAfterSingleAdd));
            testMethods.Add(new TestMethod(testFixture.VerifyRepositoryAfterMultipleAdds));
            testMethods.Add(new TestMethod(testFixture.VerifyRepositoryAfterSingleUpdate));
            testMethods.Add(new TestMethod(testFixture.VerifyRepositoryAfterSingleRemove));
            testMethods.Add(new TestMethod(testFixture.VerifyRepositoryQueryResults));
            // LATER: Add "testMethods.Add(new TestMethod(testFixture.VerifyRepositoryPersistsAllProperties));"         
            // LATER: Add code to include custom-tests

            return testMethods;
        }
    }
}